package com.class05;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/a")
public class ServletA extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req,
                           HttpServletResponse resp) throws ServletException, IOException {
        Cookie cookie = new Cookie("username", "zhangsan");
        Cookie cookie1 = new Cookie("name", "lisi");
//        setMaxAge(int seconds) 设置cookie的有效时间，单位为秒
//        cookie.setMaxAge(10);
//        setPath(String path) 设置cookie的请求有效路径
        cookie.setPath("/b");
        resp.addCookie(cookie);

        resp.addCookie(cookie1);
        resp.getWriter().write("ok");



    }
}
